#coding=utf-8
'''
Created on
@author: liyinhui
@moduleName: job.models
@description:
'''
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User

import config.constants as constants
from office.models import Office

#-----公司-------------------------------------------------------------------
class Company(models.Model):
    is_top = models.CharField('置顶显示', max_length=10, choices=constants.YESNO_CHOICES)
    office = models.ForeignKey(Office, verbose_name='所在写字楼', null=True, blank=True)
    user = models.ForeignKey(User,verbose_name='公司管理员', null=True, blank=True)
    name = models.CharField('公司名称', max_length=200)
    address = models.CharField('详细地址', max_length=200)
    web_site = models.URLField('公司网址', verify_exists=False, max_length=200, null=True, blank=True)
    telephone = models.CharField('联系电话', max_length=200, null=True, blank=True)
    email = models.EmailField('电子邮箱', null=True, blank=True)
    size = models.CharField('公司规模', max_length=200, null=True, blank=True)
    kind = models.CharField('公司性质', max_length=200, null=True, blank=True)
    industry = models.CharField('所属行业', max_length=200, null=True, blank=True)
    about = models.TextField('公司简介', max_length=2000, null=True, blank=True)
    create_date = models.DateTimeField('加入时间', auto_now=True)

    def __unicode__(self):
        return "%s" % self.name

    def get_absolute_url(self):
        return "/job/company/%s/" % self.id

    class Meta:
        ordering = ['-is_top','-id']
        verbose_name = '公司'
        verbose_name_plural = '%s管理' % verbose_name



class CompanyAdmin(admin.ModelAdmin):
    list_display = ('id','is_top', 'office', 'name','user','create_date')
admin.site.register(Company, CompanyAdmin)


#----公司相册---------------------------------------------------------
class CompanyAlbum(models.Model):
    company = models.ForeignKey(Company, verbose_name='公司')
    src = models.ImageField(upload_to='album',verbose_name='上传图片')
    create_date = models.DateTimeField('上传时间', auto_now=True)
    class Meta:
        ordering = ['-id']
        verbose_name = '公司图片'
        verbose_name_plural = '%s管理' % verbose_name

class CompanyAlbumAdmin(admin.ModelAdmin):
    list_display = ('id','company', 'src', 'create_date')
admin.site.register(CompanyAlbum, CompanyAlbumAdmin)


#----工作----------------------------------------------------
class Job(models.Model):
    company = models.ForeignKey(Company, verbose_name="公司")
    title = models.CharField("标   题", max_length=100)
    is_top = models.CharField("是否置顶", max_length=10, choices=constants.YESNO_CHOICES)
    is_rapid = models.CharField("是否急聘", max_length=10, choices=constants.YESNO_CHOICES)
    category = models.CharField("职位类别", max_length=100, null=True, blank=True)
    kind = models.CharField("职位性质", max_length=100, null=True, blank=True)
    experience = models.CharField("经验要求", max_length=100, null=True, blank=True)
    degree = models.CharField("学历要求", max_length=100, null=True, blank=True)
    number = models.CharField("招聘人数", max_length=100, null=True, blank=True)
    salary = models.CharField("月   薪", max_length=100)
    place = models.CharField("工作地点", max_length=100)
    end_date = models.DateField("截止日期", auto_now=False)
    create_date = models.DateField("发布日期", auto_now=True)
    about = models.TextField("职位描述及其它要求", max_length=100, null=True, blank=True)

    def __unicode__(self):
        return "%s" % self.title

    def get_absolute_url(self):
        return "/job/detail/%s/" % self.id

    class Meta:
        ordering = ["-is_top","-id"]
        verbose_name = "公司招聘"
        verbose_name_plural = "%s管理" % verbose_name


class JobAdmin(admin.ModelAdmin):
    list_display = ("id","is_top","company","title","salary","create_date","end_date")

admin.site.register(Job, JobAdmin)